<template>
  <div id="app">
    <router-view/>
  </div>
</template>

<script>
import FootMessage from '@/components/foot-message/index.vue'
import { setStorage } from "@/utils/storage";
import{mapActions,mapState} from "vuex"
export default {
  components:{
    FootMessage
  },
  mounted(){
      window.addEventListener('beforeunload', e => this.beforeunloadHandler(e))
      window.addEventListener('unload', e => this.unloadHandler(e))   
      var ua = window.navigator.userAgent.toLowerCase();
      if (ua.match(/MicroMessenger/i) == 'micromessenger') {
          var dataForWeixin={
            title:"【躺猪网】超值好铺抢租中",
            imgUrl:"https://www.tangzhezu.com/static/map.png",
            link:window.location.href,
            desc:"好铺好服务 找铺上躺猪"
          }
          this.$share.getJSSDK(dataForWeixin)
      }
  },
  watch:{
    $route:{
      handler(val,oldval){
        console.log(val);//新路由信息
        console.log(oldval);//老路由信息
        if(oldval.path=="/"){
          this.saveRouter(1)
        }
      },
      // 深度观察监听
      deep: true
    }
  },
  destroyed() {
      window.removeEventListener('beforeunload', e => this.beforeunloadHandler(e))
      window.removeEventListener('unload', e => this.unloadHandler(e))
  },
  computed:{
    ...mapState(["vuexEngineerForm","vuexqueryForm"]),
  },
  methods: {
    ...mapActions(["SaveUserEngineerSelect","SaveUserSelect","saveRouter"]),
      beforeunloadHandler(){
        this._beforeUnload_time=new Date().getTime();
     },
     unloadHandler(e){
        this._gap_time=new Date().getTime()-this._beforeUnload_time;
        debugger
        //判断是窗口关闭还是刷新
        if(this._gap_time<=5){
          //如果是登录状态，关闭窗口前，移除用户
          var vuexqueryForm={
            area: "", // 店铺面积
            district: "", // 地区
            format: "", // 业态
            keywords: "",
            pageNumber: 1,
            pageSize: 5,
            rent: "", // 价格
            sortColumn:null, //排序字段(1:时间排序，2:价格，3:面积)
            sortType:1  //排序字段(0:倒叙，1:正序)
          }
          var vuexEngineerForm={
            keywords:"",
            // 省id
            province:"",
            // 市id
            city:"",
            // 区id
            district:"",
            // 省名
            provinceName:"",
            // 市名
            cityName:"",
            // 区名
            districtName:"",
            area: "", // 店铺面积
            district: "", // 地区
            format: "", // 业态
            rent: "", // 价格
            pageNumber: 1,
            pageSize: 5,
            hot:3, // 热度排序 (1正序,0倒叙)
            time:3, //时间排序(1正序,0倒叙)
            weight:0,
            wordfromChild:""
          }
          // 传默认值到缓存
          this.SaveUserSelect(vuexqueryForm); 
          this.SaveUserEngineerSelect(vuexEngineerForm); 
          this.saveRouter(0)
        }else{
          const{vuexEngineerForm,vuexqueryForm}=this
          vuexEngineerForm.pageNumber=1
          vuexqueryForm.pageNumber=1
          this.SaveUserEngineerSelect(vuexEngineerForm); 
          this.SaveUserSelect(vuexqueryForm)// 存入Vuex
        }
     },
  },
};
</script>

<style lang="less">
@import "./utils/styles/base.less"; // 重置样式
</style>
